<template>
    <div>
      <el-form inline :model="queryData" ref="queryData" class="query-form">

        <el-form-item label="评论内容:" prop="content">
          <el-input v-model="queryData.content" placeholder="请输入" style="width: 200px" clearable
                    @clear="formClear('content')"/>
        </el-form-item>
        <el-form-item label="评论人手机:" prop="phone">
          <el-input v-model="queryData.phone" placeholder="请输入" style="width: 200px" clearable
                    @clear="formClear('phone')"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查 询</el-button>
          <el-button @click="onReset">重 置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableList" border style="width: 100%;">
        <el-table-column prop="id" label="评论ID" align="center" width="90"/>
        <el-table-column prop="content" label="评论内容" align="center" width="400" show-overflow-tooltip/>
        <el-table-column prop="phone" label="评论人手机" align="center" />
        <el-table-column prop="wxUserId" label="评论人Uid" align="center"/>
        <el-table-column prop="createTime" label="添加时间" align="center" />
        <el-table-column label="操作" align="center" width="150" fixed="right">
          <template slot-scope="{row}">
            <el-button type="text" @click="deleteEvent(row)">删 除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <Paging v-model="queryData" @change="getRequest"></Paging>
    </div>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    computed: {
      ...mapGetters(['confirm'])
    },
    name: 'commentList',
    data() {
      return {
        tableList: [],
        resourceList: [],
        queryData: {
          informationId: null,
          content: null, phone: null,
          pageNum: 1,
          pageSize: 10,
          total: 0
        },
        entity: null,
        drawer: false
      }
    },
    beforeMount() {
      this.queryData.informationId = this.$route.query.detailId || null
      this.getRequest()
    },
    methods: {
      /**
       * 删除事件
       */
      deleteEvent(row) {
        this.$confirm('确认要删除该数据吗?', '提示', this.confirm.options).then(async() => {
          await this.$ajax.get(`/wx/informationComment/remove?id=${row.id}`)
          this.$message.success('操作成功!')
          this.getRequest()
        })
      },
      /**
       * 重置事件
       */
      onReset() {
        this.queryData.pageNum = 1
        this.$refs['queryData'].resetFields()
        this.getRequest()
      },
      /**
       * 查询条件提交事件
       */
      onSubmit() {
        this.queryData.pageNum = 1
        this.getRequest()
      },
      /**
       * 列表请求事件
       */
      async getRequest() {
        const params = JSON.parse(JSON.stringify(this.queryData))
        const res = await this.$ajax.get('/wx/informationComment/backstage/list', { params })
        this.queryData.total = res.total
        this.tableList = res.rows
      },
      /**
       * form-input 置空事件
       */
      formClear(key) {
        this.queryData[key] = null
        this.onSubmit()
      }
    }
  }
</script>

<style scoped>

</style>
